<?php
$is_defend=true;
include_once '../includes/common.php';
if($islogin2==1){}else sysmsg("您还未登录，请先登录",2,'./login.php',true);

$day = date("Y-m-d");
$lastday = date("Y-m-d",strtotime("-1 day"));
if ($row = $DB->get_row("SELECT * FROM authguao_qiandao WHERE uid='{$userrow['uid']}' and date='$day' order by id desc limit 1")) {
    $isqiandao = true;
    $continue = $row['continue'];
}else{
    if ($row = $DB->get_row("SELECT * FROM authguao_qiandao WHERE uid='{$userrow['uid']}' and date='$lastday' order by id desc limit 1")) {
        $continue = $row['continue'];
    }else{
        $continue = 0;
    }
    $isqiandao = false;
}

$rs=$DB->query("SELECT * FROM authguao_qiandao order by id desc limit 10");
$qqrow=array();
$qdrow=array();
while($res = $DB->fetch($rs)){
    if(count($qqrow)<5){
        $qqrow[]=$res['qq'];
    }
    $qdrow[]=$res;
}

$title = '每日签到';
include_once './header.php';
if($conf['qiandao_open']!=1)showmsg('错误', '授权平台未开放每日签到功能！', 4, './');
?>
<style>
.img-circle{width: 15%!important;}
</style>
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                签到说明
            </div>
            <div class="card-body">
                <div class="layui-elem-quote">每日签到需要消耗<?php echo $conf['qiandao_money']?>元的签到费用哦！<hr>签到最低可获得<?php echo $conf['qiandao_min'];?>元<br>签到最高可获得<?php echo $conf['qiandao_max'];?>元</div>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                每日签到
            </div>
            <div class="card" style="position: relative;">
                <img class="" style="width: 100%;height: 175px;" src="../assets/img/qiandao.jpg">
                <div style="top: 0;left: 0;padding: 15px;position: absolute;">
                    <iframe width="300" scrolling="no" height="60" frameborder="0" allowtransparency="true" src="//i.tianqi.com/index.php?c=code&id=12&icon=1&num=2&site=12"></iframe>
                </div>
                <div style="bottom: 0;right: 0;padding: 15px;position: absolute;">
                    <h5 class="widget-heading">
                        <font color="#fff" style="text-shadow: black 3px 3px 3px;font-size: 22px;">
                            <strong>总奖励：<span id="rewardcount">0.00</span>元</strong>
                        </font>
                    </h5>
                    <h5 class="widget-heading block-right">
                        <font color="#fff" style="text-shadow: black 3px 3px 3px;font-size: 22px;">
                            <strong><i class="fa fa-calendar-check-o"></i> 连续签到<?php echo $continue?>天</strong>
                        </font>
                    </h5>
                </div>
            </div>
            <div class="card-footer">
                <button type="button" class="btn btn-block btn-xs btn-outline-success" id="qiandao"><span style="font-size:16px" ><b><i class="fa fa-check-square"></i> <?php echo $isqiandao==true?'今天已签到':'立即签到';?></b></span></button>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                签到说明
            </div>
            <div class="card-body">
                <div class="avatar-group">
                <?php
                foreach($qqrow as $row){
                    echo '<img src="http://q4.qlogo.cn/headimg_dl?dst_uin='.$row.'&spec=640" class="img-rounded img-circle img-thumbnail">';
                }
                ?>
                </div>
            </div>
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th style="font-size: 13px;" class="text-center">
                            <i class="fa fa-user-circle-o"></i> 今日签到<br><span id="count1"></span>人
                        </th>
                        <th style="font-size: 13px;" class="text-center">
                            <i class="fa fa-user-circle"></i> 昨日签到<br><span id="count2"></span>人
                        </th>
                        <th style="font-size: 13px;" class="text-center">
                            <i class="fa fa-pie-chart"></i> 累计签到<br><span id="count3"></span>人
                        </th>
                    </tr>
                </thead>
                <tbody>
                <?php
                foreach($qdrow as $row){
                    if($row['reward']=='0.00'){
                        $text='签到成功,但未获得奖励';
                    }else{
                        $text='签到获得奖励'.$row['reward'].'元!';
                    }
                    echo '<tr><th colspan="3" style="font-size: 13px;"><span class="pull-right label label-info"><small>连续'.$row['continue'].'天</small></span><i class="fa fa-user"></i> UID:'.$row['uid'].' 在'.date("H:i",strtotime($row['time'])).$text.'</th></tr>';
                }
                ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<?php
include_once './bottom.php';
?>
<script type="text/javascript">
$(document).ready(function(){
    $("#qiandao").click(function(){
        $.ajax({
         type: "get",
         url: "ajax.php?act=qiandao",
         dataType: "json",
         success: function(data){
            if(data.code == 0){
                layer.msg(data.msg, {
                    icon: 6,
                    end: function (layero, index) {
                        window.location.reload();
                    }
                });
            } else {
                layer.msg(data.msg, {icon: 5});
            }
         },
         error: function(){
             layer.msg('签到失败，请稍后刷新重试！', {icon: 5}); 
         }
       });
    });
    $.ajax({
        type : "GET",
        url : "ajax.php?act=qdcount",
        dataType : 'json',
        async: true,
        success : function(data) {
            $('#count1').html(data.count1);
            $('#count2').html(data.count2);
            $('#count3').html(data.count3);
            $('#rewardcount').html(data.rewardcount);
        }
    });
})
</script>